package com.manage.platform.controller;

import com.manage.platform.dto.MenuDto;
import com.manage.platform.dto.query.MenuPageQuery;
import com.manage.platform.service.impl.MenuServiceImpl;
import com.manage.platform.utils.R;
import com.manage.platform.utils.RPage;
import com.manage.platform.vo.CommonVo;
import com.manage.platform.vo.MenuTreeVo;
import com.manage.platform.vo.MenuVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * YWD
 * 2025/9/24
 */
@AllArgsConstructor
@RestController
@RequestMapping("/menu")
@Tag(name = "系统设置-菜单权限管理")
public class MenuController {

    private final MenuServiceImpl menuService;

    @GetMapping("/getMenuTree")
    @Operation(summary = "查询菜单列表(树形)")
    public R<List<MenuTreeVo>> getMenuTree() {
        return R.ok(menuService.getMenuTree());
    }

    @PostMapping("/getMenuPage")
    @Operation(summary = "查询菜单列表(分页)")
    public R<RPage<List<MenuVo>>> getMenuPage(@RequestBody MenuPageQuery query) {
        return R.ok(menuService.getMenuPage(query));
    }

    @GetMapping("/getMenuDetails/{id}")
    @Operation(summary = "查询菜单详情")
    public R<MenuVo> getMenuDetails(@Schema(description = "ID") @PathVariable("id") Long id) {
        return R.ok(menuService.getMenuDetails(id));
    }

    @PostMapping("/saveMenu")
    @Operation(summary = "添加菜单")
    public R<Boolean> saveMenu(@RequestBody MenuDto dto) {
        return R.ok(menuService.saveMenu(dto));
    }

    @PutMapping("/updateMenu")
    @Operation(summary = "修改菜单")
    public R<Boolean> updateMenu(@RequestBody MenuDto dto) {
        return R.ok(menuService.updateMenu(dto));
    }

    @DeleteMapping("/deleteMenu/{id}")
    @Operation(summary = "删除菜单")
    public R<Boolean> deleteMenu(@Schema(description = "ID") @PathVariable("id") Long id) {
        return R.ok(menuService.deleteMenu(id));
    }

    @DeleteMapping("/deleteBatchMenu")
    @Operation(summary = "批量删除菜单")
    public R<Boolean> deleteBatchMenu(@RequestBody List<Long> ids) {
        return R.ok(menuService.deleteBatchMenu(ids));
    }

    /**
     * 菜单列表(筛选项)
     */
    @GetMapping("/getMenuList")
    @Operation(summary = "菜单列表(筛选项)")
    public R<List<CommonVo>> getMenuList(@Schema(description = "菜单名称")
                                         @RequestParam(value = "name", required = false) String name) {
        return R.ok(menuService.getMenuList(name));
    }

}
